import { createApp } from "vue";
import App from "./App.vue";
import "./style.css";
import router from "./router";
import pinia from "./store";
import axios from "./axios/index";
import i18n from "./locals";
import "animate.css";
import "element-plus/theme-chalk/dark/css-vars.css";
import dom from "./common/api/dom";

window.dom = dom;

// import { registerSW } from "virtual:pwa-register";

// const updateSW = registerSW({
//   onOfflineReady() {},
// });
//echarts.js分界线

import * as echarts from "echarts/core";
import {
  BarChart,
  // 系列类型的定义后缀都为 SeriesOption
  BarSeriesOption,
  // LineChart,
  LineSeriesOption,
  LineChart,
  MapChart,
  PieChart,
} from "echarts/charts";
import {
  TitleComponent,
  // 组件类型的定义后缀都为 ComponentOption
  TitleComponentOption,
  TooltipComponent,
  TooltipComponentOption,
  GridComponent,
  GridComponentOption,
  // 数据集组件
  DatasetComponent,
  DatasetComponentOption,
  // 内置数据转换器组件 (filter, sort)
  TransformComponent,
  VisualMapComponent,
  LegendComponent,
  ToolboxComponent,
} from "echarts/components";
import { LabelLayout, UniversalTransition } from "echarts/features";
import { CanvasRenderer } from "echarts/renderers";

// 通过 ComposeOption 来组合出一个只有必须组件和图表的 Option 类型
type ECOption = echarts.ComposeOption<
  | BarSeriesOption
  | LineSeriesOption
  | TitleComponentOption
  | TooltipComponentOption
  | GridComponentOption
  | DatasetComponentOption
>;

// 注册必须的组件
echarts.use([
  TitleComponent,
  TooltipComponent,
  GridComponent,
  DatasetComponent,
  TransformComponent,
  BarChart,
  LabelLayout,
  UniversalTransition,
  CanvasRenderer,
  MapChart,
  VisualMapComponent,
  LegendComponent,
  LineChart,
  ToolboxComponent,
  PieChart,
]);

const option: ECOption = {
  // ...
};

//echarts.js分界线

//MD编辑器分界线

import VueMarkdownEditor from "@kangc/v-md-editor";
import "@kangc/v-md-editor/lib/style/base-editor.css";
import vuepressTheme from "@kangc/v-md-editor/lib/theme/vuepress.js";
import "@kangc/v-md-editor/lib/theme/style/vuepress.css";

// //代码高亮
import Prism from "prismjs";
//代码行号
import createLineNumbertPlugin from "@kangc/v-md-editor/lib/plugins/line-number/index";

//高亮代码行
import createHighlightLinesPlugin from "@kangc/v-md-editor/lib/plugins/highlight-lines/index";
import "@kangc/v-md-editor/lib/plugins/highlight-lines/highlight-lines.css";
//快捷复制
import createCopyCodePlugin from "@kangc/v-md-editor/lib/plugins/copy-code/index";
import "@kangc/v-md-editor/lib/plugins/copy-code/copy-code.css";

VueMarkdownEditor.use(vuepressTheme, {
  Prism,
  codeHighlightExtensionMap: {
    vue: "xml",
    //vue:"html",
  },
  extend(md: any) {
    // md为 markdown-it 实例，可以在此处进行修改配置,并使用 plugin 进行语法扩展
    // md.set(option).use(plugin);
  },
})
  .use(createCopyCodePlugin())
  .use(createHighlightLinesPlugin())
  .use(createLineNumbertPlugin());

//MD编辑器分界线

const app = createApp(App);

app.config.globalProperties.$echarts = echarts;
app.config.globalProperties.$http = axios;

//挂载全局组件
import { Icon } from "@iconify/vue";
app.component("icon", Icon);
app.use(router).use(pinia).use(i18n).use(VueMarkdownEditor);

//挂载全局指令
import { vrouter } from "./common/directive/router";
app.directive("router", vrouter);
app.mount("#app");
